<template>
  <scroll-view scroll-y class="wrap">
    <!-- 用户基本信息 -->
    <view class="userInfo">
      <!-- 用户头像 -->
      <u-avatar :src="userForm.avatarUrl" size="150" mode="square"></u-avatar>
      <!-- 用户信息 -->
      <view class="userContent">
        <!-- 用户名 -->
        <view>
          <text class="title">用户名</text>
          <text>{{ userForm.username }}</text>
        </view>
        <!-- 用户昵称 -->
        <view>
          <text class="title">昵称</text>
          <text>{{ userForm.nickname }}</text>
        </view>
        <!-- 用户电话 -->
        <view>
          <text class="title">电话</text>
          <text>{{ userForm.phone }}</text>
        </view>
        <!-- 用户邮箱 -->
        <view>
          <text class="title">邮箱</text>
          <text>{{ userForm.email }}</text>
        </view>
        <!-- 用户角色 -->
        <view>
          <text class="title">角色</text>
          <text>{{ roleName }}</text>
        </view>
      </view>
      <!-- 用户详细信息 -->
      <view class="playerInfo" v-if="roleId === 1 && playerInfoForm.id">
        <view>
          <text class="title">姓名</text>
          <text>{{ playerInfoForm.name }}</text>
        </view>
        <view>
          <text class="title">年龄</text>
          <text>{{ playerInfoForm.age }}</text>
        </view>
        <view>
          <text class="title">身高</text>
          <text>{{ playerInfoForm.height }}</text>
        </view>
        <view>
          <text class="title">体重</text>
          <text>{{ playerInfoForm.weight }}</text>
        </view>
        <view>
          <text class="title">训练进球数</text>
          <text>{{ playerInfoForm.train_goals }}</text>
        </view>
        <view>
          <text class="title">训练助攻数</text>
          <text>{{ playerInfoForm.train_assist }}</text>
        </view>
        <view>
          <text class="title">训练抢断数</text>
          <text>{{ playerInfoForm.train_steal }}</text>
        </view>
        <view>
          <text class="title">训练失误数</text>
          <text>{{ playerInfoForm.train_mistake }}</text>
        </view>
        <view>
          <text class="title">训练犯规数</text>
          <text>{{ playerInfoForm.train_foul }}</text>
        </view>
        <view>
          <text class="title">比赛进球数</text>
          <text>{{ playerInfoForm.match_goals }}</text>
        </view>
        <view>
          <text class="title">比赛助攻数</text>
          <text>{{ playerInfoForm.match_assist }}</text>
        </view>
        <view>
          <text class="title">比赛抢断数</text>
          <text>{{ playerInfoForm.match_steal }}</text>
        </view>
        <view>
          <text class="title">比赛失误数</text>
          <text>{{ playerInfoForm.match_mistake }}</text>
        </view>
        <view>
          <text class="title">比赛犯规数</text>
          <text>{{ playerInfoForm.match_foul }}</text>
        </view>
        <view>
          <u-button type="warning" @click="updatePlayerInfoShow = true"
            >修改</u-button
          >
          <u-button type="error" @click="deletePlayerInfoShow = true"
            >删除</u-button
          >
        </view>
      </view>
      <!-- 教练详细信息 -->
      <view class="coachInfo" v-if="roleId === 2 && coachInfoForm.id">
        <view>
          <text class="title">姓名</text>
          <text>{{ coachInfoForm.name }}</text>
        </view>
        <view>
          <text class="title">年龄</text>
          <text>{{ coachInfoForm.age }}</text>
        </view>
        <view>
          <text class="title">性别</text>
          <text>{{ coachInfoForm.gender | genderFilter }}</text>
        </view>
        <view>
          <text class="title">生日</text>
          <text>{{ coachInfoForm.birthday }}</text>
        </view>
        <view>
          <u-button type="warning" @click="updateCoachInfoShow = true"
            >修改</u-button
          >
          <u-button type="error" @click="deleteCoachInfoShow = true"
            >删除</u-button
          >
        </view>
      </view>
    </view>

    <!-- 按钮区域 -->
    <view class="btnGroup">
      <u-button type="primary" :ripple="true" @click="updateUserShow = true"
        >修改用户信息</u-button
      >
      <u-button type="primary" :ripple="true" @click="updatePwdShow = true"
        >修改用户密码</u-button
      >
      <u-button
        v-if="roleId === 1 && !playerInfoForm.id"
        type="success"
        :ripple="true"
        @click="addPlayerInfoShow = true"
        >添加真实信息</u-button
      >
      <u-button
        v-if="roleId === 2 && !coachInfoForm.id"
        type="success"
        :ripple="true"
        @click="addCoachInfoShow = true"
        >添加教练信息</u-button
      >
      <u-button
        type="warning"
        v-if="roleId === 3"
        :ripple="true"
        @click="toAllUser"
        >获取所有用户</u-button
      >
      <u-button
        type="warning"
        v-if="roleId === 3"
        :ripple="true"
        @click="toAllPlayerInfo"
        >获取所有球员</u-button
      >
      <u-button
        type="warning"
        v-if="roleId === 3"
        :ripple="true"
        @click="toAllCoachInfo"
        >获取所有教练</u-button
      >
    </view>
    <!-- 弹出层 -->
    <!-- 修改用户信息 -->
    <u-popup
      v-model="updateUserShow"
      mode="bottom"
      border-radius="10"
      closeable
    >
      /
      <view style="padding: 15rpx 30rpx">
        <u-form :model="userForm" ref="userFormRef" :error-type="['message']">
          <u-form-item label="用户名" prop="username" label-width="150rpx">
            <u-input v-model="userForm.username"></u-input>
          </u-form-item>
          <u-form-item label="昵称" prop="nickname" label-width="150rpx">
            <u-input v-model="userForm.nickname"></u-input>
          </u-form-item>
          <u-form-item label="电话" prop="phone" label-width="150rpx">
            <u-input type="digit" v-model="userForm.phone"></u-input>
          </u-form-item>
          <u-form-item label="邮箱" prop="email" label-width="150rpx">
            <u-input v-model="userForm.email"></u-input>
          </u-form-item>
          <u-form-item label="头像" label-width="150rpx">
            <u-upload
              :action="action"
              :max-size="5 * 1024 * 1024"
              max-count="1"
              @on-success="avatarUpload"
            ></u-upload>
          </u-form-item>
          <u-button
            type="primary"
            shape="circle"
            :ripple="true"
            @click="updateUser"
            >提交</u-button
          >
        </u-form>
      </view>
    </u-popup>
    <!-- 修改用户密码 -->
    <u-popup v-model="updatePwdShow" mode="bottom" border-radius="10" closeable>
      <view style="padding: 50rpx 30rpx">
        <u-form
          :model="updatePwdForm"
          ref="updatePwdFormRef"
          :error-type="['message']"
        >
          <u-form-item label="旧密码" prop="oldPass" label-width="150rpx">
            <u-input
              type="password"
              v-model="updatePwdForm.oldPass"
              placeholder="请输入旧密码"
            ></u-input>
          </u-form-item>
          <u-form-item label="新密码" prop="pass" label-width="150rpx">
            <u-input
              type="password"
              v-model="updatePwdForm.pass"
              placeholder="请输入新密码"
            ></u-input>
          </u-form-item>
          <u-button
            type="primary"
            shape="circle"
            :ripple="true"
            @click="updatePwd"
            >提交</u-button
          >
        </u-form>
      </view>
    </u-popup>
    <!-- 添加真实信息 -->
    <u-popup
      v-model="addPlayerInfoShow"
      mode="bottom"
      border-radius="10"
      closeable
    >
      <view style="padding: 50rpx 30rpx">
        <u-form
          :model="addPlayerInfoForm"
          ref="addPlayerInfoFormRef"
          :error-type="['message']"
        >
          <u-form-item label="姓名" prop="name" label-width="150rpx">
            <u-input
              v-model="addPlayerInfoForm.name"
              placeholder="请输入姓名"
            ></u-input>
          </u-form-item>
          <u-form-item label="年龄" prop="age" label-width="150rpx">
            <u-input
              type="number"
              v-model="addPlayerInfoForm.age"
              placeholder="请输入年龄"
            ></u-input>
          </u-form-item>
          <u-form-item label="身高" prop="height" label-width="150rpx">
            <u-input
              type="number"
              v-model="addPlayerInfoForm.height"
              placeholder="请输入身高"
            ></u-input>
          </u-form-item>
          <u-form-item label="体重" prop="weight" label-width="150rpx">
            <u-input
              type="number"
              v-model="addPlayerInfoForm.weight"
              placeholder="请输入体重"
            ></u-input>
          </u-form-item>
          <u-button
            type="primary"
            shape="circle"
            :ripple="true"
            @click="addPlayerInfo"
            >提交</u-button
          >
        </u-form>
      </view>
    </u-popup>
    <!-- 修改真实信息 -->
    <u-popup
      v-model="updatePlayerInfoShow"
      mode="bottom"
      border-radius="10"
      closeable
    >
      <view style="padding: 50rpx 30rpx">
        <u-form
          :model="playerInfoForm"
          ref="updatePlayerInfoFormRef"
          :error-type="['message']"
        >
          <u-form-item label="姓名" label-width="150rpx">
            <u-input v-model="playerInfoForm.name"></u-input>
          </u-form-item>
          <u-form-item label="年龄" label-width="150rpx">
            <u-input v-model="playerInfoForm.age"></u-input>
          </u-form-item>
          <u-form-item label="身高" label-width="150rpx">
            <u-input v-model="playerInfoForm.height"></u-input>
          </u-form-item>
          <u-form-item label="体重" label-width="150rpx">
            <u-input v-model="playerInfoForm.weight"></u-input>
          </u-form-item>
          <u-button
            type="primary"
            shape="circle"
            :ripple="true"
            @click="updatePlayerInfo"
            >提交</u-button
          >
        </u-form>
      </view>
    </u-popup>
    <!-- 删除真实信息 -->
    <u-popup v-model="deletePlayerInfoShow" mode="top" class="deletePlayerInfo">
      <view>
        <text>是否删除？</text>
        <view class="btn">
          <u-button type="primary" plain @click="deletePlayerInfo">是</u-button>
        </view>
        <view class="btn">
          <u-button type="error" plain @click="deletePlayerInfoShow = false"
            >否</u-button
          >
        </view>
      </view>
    </u-popup>
    <!-- 添加教练信息 -->
    <u-popup
      v-model="addCoachInfoShow"
      mode="bottom"
      border-radius="10"
      closeable
      height="1100"
    >
      <view style="padding: 50rpx 30rpx">
        <u-form
          :model="coachInfoForm"
          ref="coachInfoFormRef"
          :error-type="['message']"
        >
          <u-form-item label="姓名" prop="name" label-width="150rpx">
            <u-input
              v-model="coachInfoForm.name"
              placeholder="请输入姓名"
            ></u-input>
          </u-form-item>
          <u-form-item label="年龄" prop="age" label-width="150rpx">
            <u-input
              type="number"
              v-model="coachInfoForm.age"
              placeholder="请输入年龄"
            ></u-input>
          </u-form-item>
          <u-form-item label="性别" label-width="150rpx">
            <u-select
              v-model="showGender"
              :list="genderList"
              @confirm="selectGender"
            ></u-select>
            <view
              @click="showGender = true"
              style="
                height: 70rpx;
                width: 150rpx;
                text-align: center;
                border-bottom: 2rpx solid #82848a;
              "
              >{{ genderList[coachInfoForm.gender - 1].label }}</view
            >
          </u-form-item>
          <u-form-item label="生日" label-width="150rpx">
            <u-calendar
              v-model="showBirthday"
              @change="selectBirthday"
            ></u-calendar>
            <view
              @click="showBirthday = true"
              style="height: 70rpx; border-bottom: 2rpx solid #82848a"
              >{{ coachInfoForm.birthday }}</view
            >
          </u-form-item>
          <u-button
            type="primary"
            shape="circle"
            :ripple="true"
            @click="addCoachInfo"
            >提交</u-button
          >
        </u-form>
      </view>
    </u-popup>
    <!-- 修改教练信息 -->
    <u-popup
      v-model="updateCoachInfoShow"
      mode="bottom"
      border-radius="10"
      height="1100"
      closeable
    >
      <view style="padding: 50rpx 30rpx">
        <u-form
          :model="coachInfoForm"
          ref="updateCoachInfoFormRef"
          :error-type="['message']"
        >
          <u-form-item label="姓名" label-width="150rpx">
            <u-input v-model="coachInfoForm.name"></u-input>
          </u-form-item>
          <u-form-item label="年龄" label-width="150rpx">
            <u-input v-model="coachInfoForm.age"></u-input>
          </u-form-item>
          <u-form-item label="性别" label-width="150rpx">
            <u-select
              v-model="showGender"
              :list="genderList"
              @confirm="selectGender"
            ></u-select>
            <view
              @click="showGender = true"
              style="
                height: 70rpx;
                width: 150rpx;
                text-align: center;
                border-bottom: 2rpx solid #82848a;
              "
              >{{ coachInfoForm.gender | genderFilter }}</view
            >
          </u-form-item>
          <u-form-item label="生日" label-width="150rpx">
            <u-calendar
              v-model="showBirthday"
              @change="selectBirthday"
            ></u-calendar>
            <view
              @click="showBirthday = true"
              style="height: 70rpx; border-bottom: 2rpx solid #82848a"
              >{{ coachInfoForm.birthday }}</view
            >
          </u-form-item>
          <u-button
            type="primary"
            shape="circle"
            :ripple="true"
            @click="updateCoachInfo"
            >提交</u-button
          >
        </u-form>
      </view>
    </u-popup>
    <!-- 删除教练信息 -->
    <u-popup v-model="deleteCoachInfoShow" mode="top" class="deleteCoachInfo">
      <view>
        <text>是否删除？</text>
        <view class="btn">
          <u-button type="primary" plain @click="deleteCoachInfo">是</u-button>
        </view>
        <view class="btn">
          <u-button type="error" plain @click="deleteCoachInfoShow = false"
            >否</u-button
          >
        </view>
      </view>
    </u-popup>
    <!-- 显示toast提示 -->
    <u-toast ref="userToastRef" />
  </scroll-view>
</template>

<script>
export default {
  data() {
    return {
      // 用户角色
      roleName: "",
      roleId: 0,
      // 控制修改用户信息的显示与隐藏
      updateUserShow: false,
      // 控制修改用户密码的显示与隐藏
      updatePwdShow: false,
      // 控制添加真实信息
      addPlayerInfoShow: false,
      updatePlayerInfoShow: false,
      deletePlayerInfoShow: false,
      updateCoachInfoShow: false,
      deleteCoachInfoShow: false,
      // 控制添加教练信息
      addCoachInfoShow: false,
      // 展示性别选择
      showGender: false,
      // 展示生日选择
      showBirthday: false,
      genderList: [
        { value: 1, label: "男" },
        { value: 2, label: "女" },
      ],

      playerInfoForm: {
        id: "",
        name: "",
        age: "",
        height: "",
        weight: "",
        match_assist: "",
        match_foul: "",
        match_goals: "",
        match_mistake: "",
        match_steal: "",
        train_assist: "",
        train_foul: "",
        train_goals: "",
        train_mistake: "",
        train_steal: "",
      },
      coachInfoForm: {
        id: "",
        name: "",
        gender: "",
        age: "",
        birthday: "",
      },
      // 修改用户信息表单
      userForm: {
        // 用户id
        id: "",
        // 用户名
        username: "",
        // 用户昵称
        nickname: "",
        // 用户头像
        avatarUrl: "",
        // 用户电话
        phone: "",
        // 用户邮箱
        email: "",
        // 是否可用
        isenabled: true,
      },
      userFormRule: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 5,
            max: 15,
            message: "用户名必须在5-15位之间",
            trigger: "blur",
          },
        ],
        nickname: [{ required: true, message: "请输入昵称", trigger: "blur" }],
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { len: 11, message: "手机号必须为11位", trigger: "blur" },
          {
            pattern: /^\d*$/g,
            transform(value) {
              return String(value);
            },
            message: "手机号只能包含数字",
            trigger: "blur",
          },
        ],
        email: [
          { required: true, message: "请输入邮箱", trigger: "blur" },
          { type: "email", message: "请输入合法邮箱格式", trigger: "blur" },
        ],
      },
      // 修改用户密码表单
      updatePwdForm: {
        oldPass: "",
        pass: "",
        userid: "",
      },
      updatePwdFormRule: {
        oldPass: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 3,
            max: 18,
            message: "密码必须在3-18位之间",
            trigger: "blur",
          },
        ],
        pass: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 3,
            max: 18,
            message: "密码必须在3-18位之间",
            trigger: "blur",
          },
        ],
      },
      addPlayerInfoForm: {
        name: "",
        age: "",
        height: "",
        weight: "",
      },
      addPlayerInfoFormRule: {
        name: [
          { required: true, message: "请输入姓名", trigger: "change" },
          {
            min: 2,
            max: 4,
            message: "姓名必须为2-4字之间",
            trigger: "blur",
          },
        ],
        age: [{ required: true, message: "请输入年龄", trigger: "change" }],
        height: [
          { required: true, message: "请输入身高", trigger: "change" },
          { type: "float", message: "必须为小数", trigger: "blur" },
          { max: 4, message: "身高不超过三位数", trigger: "blur" },
        ],
        weight: [
          { required: true, message: "请输入体重", trigger: "change" },
          { type: "float", message: "必须为小数", trigger: "blur" },
          { max: 6, message: "体重不超过5位数", trigger: "blur" },
        ],
      },
      coachInfoFormRule: {
        name: [
          { required: true, message: "请输入姓名", trigger: "change" },
          {
            min: 2,
            max: 4,
            message: "姓名必须为2-4字之间",
            trigger: "blur",
          },
        ],
        age: [{ required: true, message: "请输入年龄", trigger: "change" }],
      },
      // 上传头像路径
      action: "http://basketballManage.mooncode.cn/upload/",
    };
  },
  methods: {
    // 获取当前用户信息
    async getCurrentUserInfo() {
      const { data } = await this.$request({
        url: "/user/currentUser",
      });
      this.userForm.username = data.username;
      this.userForm.avatarUrl = data.avatar;
      this.userForm.nickname = data.nickname;
      this.userForm.phone = data.phone;
      this.userForm.email = data.email;
      this.roleName = data.roles[0].nameZh;
      this.userForm.id = data.id;
      this.updatePwdForm.userid = data.id;
      // 判断当前角色是否为管理员
      let rid = uni.getStorageSync("userInfo").roleid;
      this.roleId = rid;
    },

    // 获取当前球员信息
    async getCurrentPlayerInfo() {
      const { data } = await this.$request({
        url: "/playerinfo/currentPlayer",
      });
      this.playerInfoForm.id = data.id;
      this.playerInfoForm.name = data.name;
      this.playerInfoForm.age = data.age;
      this.playerInfoForm.height = data.height;
      this.playerInfoForm.weight = data.weight;
      this.playerInfoForm.match_assist = data.match_assist;
      this.playerInfoForm.match_foul = data.match_foul;
      this.playerInfoForm.match_goals = data.match_goals;
      this.playerInfoForm.match_mistake = data.match_mistake;
      this.playerInfoForm.match_steal = data.train_steal;
      this.playerInfoForm.train_assist = data.train_assist;
      this.playerInfoForm.train_foul = data.train_foul;
      this.playerInfoForm.train_goals = data.train_goals;
      this.playerInfoForm.train_mistake = data.train_mistake;
      this.playerInfoForm.train_steal = data.train_steal;
    },

    // 获取当前教练信息
    async getCurrentCoachInfo() {
      const { data } = await this.$request({
        url: "/coachinfo/currentCoach",
      });
      this.coachInfoForm.id = data.id;
      this.coachInfoForm.name = data.name;
      this.coachInfoForm.age = data.age;
      this.coachInfoForm.gender = data.gender;
      this.coachInfoForm.birthday = data.birthday;
    },

    // 更新用户信息
    updateUser() {
      this.$refs.userFormRef.validate(async (valid) => {
        if (valid) {
          const { data } = await this.$request({
            url: "/user/",
            method: "put",
            data: this.userForm,
          });
          if (data.code === 200) {
            this.updateUserShow = false;
            return this.$refs.userToastRef.show({
              title: data.message,
              type: "success",
            });
          } else {
            return this.$refs.userToastRef.show({
              title: data.message,
              type: "error",
            });
          }
        }
        return this.$refs.userToastRef.show({
          title: "输入不合法，请检查！",
          type: "error",
        });
      });
    },

    // 上传头像
    avatarUpload(data) {
      this.userForm.avatarUrl = data.object.avatarUrl;
    },

    // 更新用户密码
    updatePwd() {
      this.$refs.updatePwdFormRef.validate(async (valid) => {
        if (valid) {
          const { data } = await this.$request({
            url: "/user/updatePassword",
            method: "put",
            data: this.updatePwdForm,
          });
          if (data.code === 200) {
            this.updatePwdShow = false;
            return this.$refs.userToastRef.show({
              title: data.message,
              type: "success",
            });
          } else {
            return this.$refs.userToastRef.show({
              title: data.message,
              type: "error",
            });
          }
        } else {
          return this.$refs.userToastRef.show({
            title: "输入不合法，请检查！",
            type: "error",
          });
        }
      });
    },

    // 添加真实信息
    addPlayerInfo() {
      this.$refs.addPlayerInfoFormRef.validate(async (valid) => {
        if (valid) {
          const { data } = await this.$request({
            url: "/playerinfo/",
            method: "post",
            data: this.addPlayerInfoForm,
          });
          if (data.code === 200) {
            this.addPlayerInfoShow = false;
            return uni.reLaunch({
              url: "/pages/user/index",
            });
          } else {
            return this.$refs.userToastRef.show({
              title: data.message,
              type: "error",
            });
          }
        } else {
          return this.$refs.userToastRef.show({
            title: "输入不合法，请检查！",
            type: "error",
          });
        }
      });
    },

    // 修改真实信息
    async updatePlayerInfo() {
      const { data } = await this.$request({
        url: "/playerinfo/",
        method: "put",
        data: this.playerInfoForm,
      });
      if (data.code === 200) {
        this.updatePlayerInfoShow = false;
        return this.$refs.userToastRef.show({
          title: data.message,
          type: "success",
        });
      } else {
        return this.$refs.userToastRef.show({
          title: data.message,
          type: "error",
        });
      }
    },

    // 删除真实信息
    async deletePlayerInfo() {
      let id = this.playerInfoForm.id;
      const { data } = await this.$request({
        url: `/playerinfo/${id}`,
        method: "delete",
      });
      if (data.code === 200) {
        this.deletePlayerInfoShow = false;
        return uni.reLaunch({
          url: "/pages/user/index",
        });
      } else {
        return this.$refs.userToastRef.show({
          title: data.message,
          type: "error",
        });
      }
    },

    // 选择性别
    selectGender(e) {
      this.coachInfoForm.gender = e[0].value;
    },

    // 选择生日
    selectBirthday(e) {
      this.coachInfoForm.birthday = e.result;
    },

    // 添加教练信息
    addCoachInfo() {
      this.$refs.coachInfoFormRef.validate(async (valid) => {
        if (valid) {
          const { data } = await this.$request({
            url: "/coachinfo/",
            method: "post",
            data: {
              name: this.coachInfoForm.name,
              age: this.coachInfoForm.age,
              gender: this.coachInfoForm.gender,
              birthday: this.coachInfoForm.birthday,
            },
          });
          if (data.code === 200) {
            this.addCoachInfoShow = false;
            return uni.reLaunch({
              url: "/pages/user/index",
            });
          } else {
            return this.$refs.coachToastRef.show({
              title: data.message,
              type: "error",
            });
          }
        } else {
          return this.$refs.coachToastRef.show({
            title: "输入不合法，请重新输入！",
            type: "error",
          });
        }
      });
    },

    // 修改教练信息
    async updateCoachInfo() {
      const { data } = await this.$request({
        url: "/coachinfo/",
        method: "put",
        data: this.coachInfoForm,
      });
      if (data.code === 200) {
        this.updateCoachInfoShow = false;
        return this.$refs.coachToastRef.show({
          title: data.message,
          type: "success",
        });
      } else {
        return this.$refs.coachToastRef.show({
          title: data.message,
          type: "error",
        });
      }
    },

    // 删除教练信息
    async deleteCoachInfo() {
      let id = this.coachInfoForm.id;
      const { data } = await this.$request({
        url: `/coachinfo/${id}`,
        method: "delete",
      });
      if (data.code === 200) {
        this.deleteCoachInfoShow = false;
        return uni.reLaunch({
          url: "/pages/user/index",
        });
      } else {
        return this.$refs.coachToastRef.show({
          title: data.message,
          type: "error",
        });
      }
    },

    // 跳转获取所有用户信息
    toAllUser() {
      uni.navigateTo({ url: "/pages/user/userInfo/index" });
    },

    // 跳转获取所有用户信息
    toAllPlayerInfo() {
      uni.navigateTo({ url: "/pages/playerInfo/index" });
    },

    // 跳转获取所有教练信息
    toAllCoachInfo() {
      uni.navigateTo({
        url: "/pages/coachInfo/index",
      });
    },
  },

  onLoad() {
    this.getCurrentUserInfo();
    this.getCurrentPlayerInfo();
    this.getCurrentCoachInfo();
  },

  onReady() {
    this.$refs.userFormRef.setRules(this.userFormRule);
    this.$refs.updatePwdFormRef.setRules(this.updatePwdFormRule);
    this.$refs.addPlayerInfoFormRef.setRules(this.addPlayerInfoFormRule);
    this.$refs.updatePlayerInfoFormRef.setRules(this.addPlayerInfoFormRule);
    this.$refs.coachInfoFormRef.setRules(this.coachInfoFormRule);
    this.$refs.updateCoachInfoFormRef.setRules(this.coachInfoFormRule);
  },
};
</script>

<style scoped lang="scss">
.wrap {
  width: 100vw;
  height: 100vh;
  .userInfo {
    position: relative;
    u-avatar {
      z-index: 1;
      position: absolute;
      top: 10rpx;
      left: 50%;
      transform: translateX(-50%);
    }

    .userContent {
      position: relative;
      top: 180rpx;
      width: 100%;
      view {
        display: flex;
        padding: 10rpx 20rpx;
        justify-content: space-between;
        align-items: center;
        background-color: #fff;
        margin-bottom: 10rpx;
        .title {
          font-weight: 800;
        }
        text {
          height: 50rpx;
        }
      }
    }

    .playerInfo,
    .coachInfo {
      position: relative;
      top: 180rpx;
      width: 100%;
      height: 300rpx;
      overflow: auto;
      view {
        display: flex;
        padding: 10rpx 20rpx;
        justify-content: space-between;
        align-items: center;
        background-color: #fff;
        margin-bottom: 10rpx;
        .title {
          font-weight: 800;
        }

        text {
          height: 50rpx;
        }
      }
    }
  }

  .btnGroup {
    padding: 20rpx;
    position: relative;
    top: 150rpx;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    display: flex;
    flex-direction: column;
    u-button {
      margin-top: 30rpx;
    }
  }

  .deletePlayerInfo,
  .deleteCoachInfo {
    view {
      padding: 10rpx 30rpx;

      text {
        font-weight: 800;
        font-size: 35rpx;
        margin-bottom: 20rpx;
      }

      .btn {
        margin: auto;
        width: 50%;
      }
    }
  }
}


</style>